package cn.deschen.search.mysql.handlers.impl;

import cn.deschen.search.constants.OpType;
import cn.deschen.search.index.IndexHandler;
import cn.deschen.search.index.adTag.AdTagObject;
import cn.deschen.search.mysql.BinlogRowData;
import cn.deschen.search.mysql.handlers.BinlogRowDataHandler;
import cn.deschen.search.mysql.utils.SerializableUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.io.Serializable;
import java.util.Map;

import static cn.deschen.search.constants.TableConstants.AdTag.*;

/**
 * @Author hanbin_chen
 * @Description 兴趣标签处理器
 * @DateTime 2021/6/15
 * @Version V1.0.0
 */
@Component
@Slf4j
public class AdTagHandler implements BinlogRowDataHandler {

    @Override
    public void handlerBinlogRowData(BinlogRowData rowData) {
        for (Map<String, Serializable> fieldValueMap : rowData.getRowDataList()) {
            AdTagObject tagObject = new AdTagObject();

            fieldValueMap.forEach((k, v) -> {
                switch (k) {
                    case COLUMN_ID:
                        tagObject.setId(SerializableUtil.parse2Long(v));
                        break;
                    case COLUMN_TAG_NAME:
                        tagObject.setTagName(SerializableUtil.parse2String(v));
                        break;
                    case COLUMN_IS_DEL:
                        tagObject.setIsDel(SerializableUtil.parse2Integer(v));
                        break;
                }
            });
            IndexHandler.handlerLevel2Index(tagObject, OpType.to(rowData.getEventType()));
        }

    }
}
